package cn.itcast.web.controller.cargo;

import cn.itcast.domain.cargo.*;
import cn.itcast.service.cargo.InvoiceService;
import cn.itcast.web.controller.BaseController;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/cargo/invoice")
@Log4j
public class InvoiceController extends BaseController {
    @Reference
    InvoiceService invoiceService;

    /**
     * 1. 发票列表
     */
    @RequestMapping("/list")
    public String list(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize) {
        log.info("执行发票列表查询开始...");
        // 查询发票
        PageInfo<CoInvoice> pageInfo = invoiceService.findByPage(pageNum, pageSize);
        request.setAttribute("pageInfo", pageInfo);
        // return "cargo/invoice/invoice-add";
        return "cargo/Invoice/invoice-list";
    }

    /**
     * 2.删除发票
     */
    @RequestMapping("/delete")
    @ResponseBody
    public boolean list(String id) {
        boolean bool = invoiceService.deteleById(id);
        if (bool) {
            return true;
        }
        return false;
    }

    /**
     * 3.跳转到添加页面
     */
    @RequestMapping("/add")
    public String Add(String weituoID) {
        //1.根据委托ID查询装箱的合同号

        //2.贸易条款获取

        request.setAttribute("报运合同号", "报运合同号");
        //在委托页面点击生成发票，把委托id传进来,再存到域中
        request.setAttribute("weituoID", weituoID);
        return "cargo/Invoice/invoice-add";
    }

    /**
     * 4.添加保存
     */
    @RequestMapping("/edit")
    public String edit(CoInvoice coInvoice) {

        //发票状态:默认草稿
        coInvoice.setStatus(0);

        return "cargo/Invoice/invoice-add";
    }


}
